﻿using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace HuaJiLedger.Helpers;

internal class HttpHelper<T>
{
    public static T Post(string url, string param)
    {
        throw new NotImplementedException();
    }

    public static T Get(string url, string param)
    {
        var client = new RestClient($"{url}?{param}");
        var request = new RestRequest
        {
            Timeout = 3000,
            Method = Method.Get
        };

        var response = client.Execute(request);

        if (response.StatusCode == HttpStatusCode.OK)
            return JsonConvert.DeserializeObject<T>(response.Content);

        else
            throw new Exception("Http request failed");
    }
}
